<?php

	//registerUser.php
	//Function used to register User/Address information stored within the database.
	//Original Creator: Paul Venn
	
	//Includes executeInsertQuery.php to assure Database Connection and SQL Execution
	include "executeInsertQuery.php";

	//Retrieves User Information from ActionScript	
	$userID = $_REQUEST['userID'];
	$userPassword = $_REQUEST['userPassword'];
	$userFirstName = $_REQUEST['userFirstName'];
	$userLastName = $_REQUEST['userLastName'];
	$userEmail = $_REQUEST['userEmail'];
	$userDOB = $_REQUEST['Day'] . "-" . $_REQUEST['Month'] . "-" . $_REQUEST['Year'];
	$addressUserID = userID;
	$addressType = $_REQUEST['addressType'];
	$addressStreetNumber = $_REQUEST['addressStreetNumber'];
	$addressStreetName = $_REQUEST['addressStreetName'];
	$addressTown = $_REQUEST['addressTown'];
	$addressPostCode = $_REQUEST['addressPostCode'];
	$addressState = $_REQUEST['addressState'];	
		
	echo registerUser($userID, $userPassword, $userFirstName, $userLastName, $userEmail, $userDOB, $addressUserID, $addressType, $addressStreetNumber, $addressStreetName, $addressTown, $addressPostCode, $addressState);

	function registerUser($userID, $userPassword, $userFirstName, $userLastName, $userDOB, $userEmail, $addressUserID, $addressType, $addressStreetNumber, $addressStreetName, $addressTown, $addressPostCode, $addressState) 
	{
		//Query used to insert the data from the Registration form into the Database
		$userQuery = 	"INSERT INTO `cp3003_09_g05`.`tblUsers` (`userID` ,`userPassword` ,`userFirstName` ,`userLastName` ,`userDOB`)
						VALUES ('" . $userID . "', '" . md5($userPassword) . "', '" . $userFirstName . "', '" . $userLastName . "', '" . $userEmail "', '" . $userDOB . "')";
		$userInsertQuery = executeInsertQuery($userQuery);				
		
		//Secondary query used to insert the User's address information into the database				
		$userAddressQuery =	"INSERT INTO `cp3003_09_g05`.`tblAddresses` (`addressUserID` ,`addressType` ,`addressStreetNumber` ,`addressStreetName` ,`addressTown` ,`addressPostCode` ,`addressState`) 
							VALUES ('" . $addressUserID . "', '" . $addressType . "', '" . $addressStreetNumber . "', '" . $addressStreetName . "', '" . $addressTown . "', '" . $addressPostCode . "', '" . $addressState . "')";		
		$userInsertAddressQuery = executeInsertQuery($userAddressQuery);	
	}
?>
